package von.seiji.cn.thread;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.LinkedList;

/**
 * @Author: SeiJi
 * @DateTime: 2022/2/7 15:45
 * @Description: 此人很懒，未写描述！
 **/
public class Operation implements Runnable {

    public Operation(Integer code) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    private Integer code;

    private static LinkedList<Integer> list = Lists.newLinkedList();

    @Override
    public void run() {
        String name = Thread.currentThread().getName();
        System.out.println("current thread-name: " + name + ", code<" + code + ">");
        synchronized (code) {
            if(list.contains(code)) {
                System.err.println("it's right of your thought about thread!!!");
            }else {
                list.add(code);
            }


            System.out.println(name + " is busy with something...");
            try {
                Thread.sleep(1500);
            } catch (InterruptedException e) {
            }
            list.remove(code);
            System.out.println(name + " has done job!!!");
        }

    }
}
